<?php


	namespace app\home\controller;


	use app\home\validate\LoginValidate;
	use think\Loader;
	use app\home\model\Member as memberModel;

	class Member extends Base
	{

		public function getUserInfo(){

			$validate = new LoginValidate();
			$validateRes = $validate->goSceneCheck('getUserInfo');
			if($validateRes){
				return error($validateRes);
			}

			Loader::import('encrypted.wxBizDataCrypt',EXTEND_PATH);

			$sessionKey = $this->request->param('session_key');
			$encryptedData = $this->request->param('encryptedData');
			$iv = $this->request->param('iv');

			$pc = new \wxBizDataCrypt(config('wxinfo.appId'), $sessionKey);

			$errCode = $pc->decryptData($encryptedData, $iv, $data );

			if($errCode !=0){
				return error('解密失败',$errCode);
			}

			$result = json_decode($data,true);

			$memberModel = new \app\home\model\Member();
			$member = $memberModel->where('id',$this->member->id)->find();

			if($member && !$member->avatar_image){
				$member->nickname = $result['nickName'];
				$member->avatar_image = $result['avatarUrl'];
				$member->save();
			}

			return success();
		}


		public function getMember(){
			return success($this->member);
		}


	}